import axios from 'axios'
export const axiosInstance = axios.create({
  baseURL: 'http://apis.imooc.com/api/',
  timeout: 5000
})

export const get = async (url: string, data: any = {}) => {
  try {
    const result = await axiosInstance({
      method: 'get',
      url,
      params: {
        ...data, icode: '38CD209A8A08B4B6'
      }
    })
    return result
  } catch (err) {
    return err
  }
}

export const post = async (url: string, data = {}) => {
  try {
    const result = await axiosInstance({
      method: 'post',
      url,
      data: {
        ...data, icode: '38CD209A8A08B4B6'
      }
    })
    return result
  } catch (err) {
    return err
  }
}

export default axiosInstance
